package com.tanhua.management.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.management.service.VideoService;
import com.tanhua.management.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("manage")
@Slf4j
public class VideoManagerController {
    @Autowired
    private VideoService videoService;

    @Reference
    private UserInfoMapper userInfoMapper;

    /**
     *      视频管理
     *          视频记录翻页
     * @param page  页尺寸
     * @param pageSize 页数
     * @param sortProp 排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @param uid 用户ID
     * @param token  铭牌
     * @return
     */
    @GetMapping("videos")
    public ResponseEntity<PageResult> queryVideo(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "sortProp",defaultValue = "created")String sortProp,
            @RequestParam(value = "sortOrder",defaultValue = "descending")String sortOrder,
            @RequestParam(value = "uid") Integer uid
            , @RequestHeader("Authorization")String token) {
         // 如果传入page小等于0, 默认为第一页
        try {
            if (page<=0){
                page=1;
            }
            PageResult pageResult = this.videoService. queryVideoList(page, pageSize,sortProp,sortOrder, uid);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询视频列表出错~ " + e);

        }

        return ResponseEntity.status(500).build();
    }
}

